﻿using System;
using System.IO;
using System.Text.RegularExpressions;

public class EgnExtractor
{
    private const string INPUT_FILE_NAME = @"..\..\..\EgnExtractor\persons.txt";

    public static void Main()
    {
        StreamReader input = new StreamReader(INPUT_FILE_NAME);
        string pattern = @"[0-9]{10}";
        using (input)
        {
            while (!input.EndOfStream)
            {
                string text = input.ReadLine();
                Match m = Regex.Match(text, pattern,RegexOptions.None);
                while (m.Success)
                {
                    string candidate = m.Value;
                    int year = int.Parse(candidate.Substring(0, 2));
                    int month = int.Parse(candidate.Substring(2, 2));
                    int day = int.Parse(candidate.Substring(4, 2));
                    try
                    {
                        DateTime birthDate = new DateTime(year, month, day);
                    }
                    catch (ArgumentOutOfRangeException ex)
                    { 
                        //date was invalid
                        m = m.NextMatch();
                        continue;
                    }
                    Console.WriteLine(m.Value);
                    m = m.NextMatch();
                }
            }
        }

    }

}
